package smdc.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import smdc.common.annotation.Log;
import smdc.common.core.controller.BaseController;
import smdc.common.core.domain.AjaxResult;
import smdc.common.enums.BusinessType;
import smdc.order.domain.DishDetail;
import smdc.order.service.IDishDetailService;
import smdc.common.utils.poi.ExcelUtil;
import smdc.common.core.page.TableDataInfo;

/**
 * 菜品规格详情Controller
 * 
 * @author maorui
 * @date 2025-03-28
 */
@RestController
@RequestMapping("/order/dishdetail")
public class DishDetailController extends BaseController
{
    @Autowired
    private IDishDetailService dishDetailService;

    /**
     * 查询菜品规格详情列表
     */
    @PreAuthorize("@ss.hasPermi('order:dishdetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(DishDetail dishDetail)
    {
        startPage();
        List<DishDetail> list = dishDetailService.selectDishDetailList(dishDetail);
        return getDataTable(list);
    }

    /**
     * 导出菜品规格详情列表
     */
    @PreAuthorize("@ss.hasPermi('order:dishdetail:export')")
    @Log(title = "菜品规格详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DishDetail dishDetail)
    {
        List<DishDetail> list = dishDetailService.selectDishDetailList(dishDetail);
        ExcelUtil<DishDetail> util = new ExcelUtil<DishDetail>(DishDetail.class);
        util.exportExcel(response, list, "菜品规格详情数据");
    }

    /**
     * 获取菜品规格详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:dishdetail:query')")
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId)
    {
        return success(dishDetailService.selectDishDetailByDetailId(detailId));
    }

    /**
     * 新增菜品规格详情
     */
    @PreAuthorize("@ss.hasPermi('order:dishdetail:add')")
    @Log(title = "菜品规格详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DishDetail dishDetail)
    {
        return toAjax(dishDetailService.insertDishDetail(dishDetail));
    }

    /**
     * 修改菜品规格详情
     */
    @PreAuthorize("@ss.hasPermi('order:dishdetail:edit')")
    @Log(title = "菜品规格详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DishDetail dishDetail)
    {
        return toAjax(dishDetailService.updateDishDetail(dishDetail));
    }

    /**
     * 删除菜品规格详情
     */
    @PreAuthorize("@ss.hasPermi('order:dishdetail:remove')")
    @Log(title = "菜品规格详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailIds}")
    public AjaxResult remove(@PathVariable Long[] detailIds)
    {
        return toAjax(dishDetailService.deleteDishDetailByDetailIds(detailIds));
    }
}
